package com.ds.infrastructure.hyperspace.console.model.request.environment;

import com.ds.infrastructure.hyperspace.console.config.validation.EnumValue;
import com.ds.infrastructure.hyperspace.console.entity.enums.TbEnvironmentEnum;
import com.ds.infrastructure.hyperspace.console.entity.table.TbEnvironment;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * @author: yaozhendong
 * @create: 2019-09-18 11:40
 **/
@Data
@NoArgsConstructor
public class UpdateEnvironmentForm {
    @NotNull
    private Long id;

    @NotBlank
    @Pattern(regexp = "^[a-zA-Z-/0-9]{2,100}$", message = "不满足正则表达式:^[a-zA-Z-/0-9]{2,100}$")
    private String environmentName;
    @NotBlank
    private String packageName;

    @EnumValue(value = TbEnvironmentEnum.USAGE_STATE.class, nullable = true)
    @ApiModelProperty(value = "使用状态(非必填):1=正常;2=关闭;")
    private Integer usageState;

    private String description;

    public static TbEnvironment toEntity(UpdateEnvironmentForm form) {
        TbEnvironment tbEnvironment = new TbEnvironment();
        tbEnvironment.setId(form.getId());
        tbEnvironment.setEnvironmentName(form.getEnvironmentName());
        tbEnvironment.setPackageName(form.getPackageName());
        tbEnvironment.setUsageState(form.getUsageState());
        tbEnvironment.setDescription(form.getDescription());
        return tbEnvironment;
    }
}
